package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduCourseRatingDTO;
import com.zenith.edu.po.vo.EduCourseRatingVO;
import com.zenith.edu.service.EduCourseRatingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/course-rating")
@Tag(name = "课程评价管理", description = "课程评价管理接口")
public class EduCourseRatingController {
    
    @Autowired
    private EduCourseRatingService eduCourseRatingService;
    
    @SecurePostMapping  (value = "/createCourseRating",roles = {"ADMIN"},permission = "courseRating:create")
    @Operation(summary = "创建课程评价")
    public Result<EduCourseRatingVO> createCourseRating(@RequestBody EduCourseRatingDTO dto) {
        EduCourseRatingVO courseRatingVO = eduCourseRatingService.createCourseRating(dto);
        return Result.success(courseRatingVO);
    }
    
    @SecurePostMapping(value = "/{id}", roles = {"ADMIN"}, permission = "courseRating:read")
    @Operation(summary = "根据ID获取课程评价详情")
    public Result<EduCourseRatingVO> getCourseRatingById(@PathVariable Long id) {
        EduCourseRatingVO courseRatingVO = eduCourseRatingService.getCourseRatingById(id);
        if (courseRatingVO == null) {
            return Result.fail("课程评价不存在");
        }
        return Result.success(courseRatingVO);
    }
    
    @SecurePostMapping(value = "/updateCourseRating", roles = {"ADMIN"}, permission = "courseRating:update")        
    @Operation(summary = "更新课程评价信息")
    public Result<EduCourseRatingVO> updateCourseRating(@RequestBody EduCourseRatingDTO dto) {
        EduCourseRatingVO courseRatingVO = eduCourseRatingService.updateCourseRating(dto);
        return Result.success(courseRatingVO);
    }
    
    @SecurePostMapping(value = "/deleteCourseRating/{id}",roles = "ADMIN",permission = "courseRating:delete")
    @Operation(summary = "删除指定课程评价")
    public Result<Void> deleteCourseRating(@PathVariable Long id) {
        boolean result = eduCourseRatingService.deleteCourseRating(id);
        if (!result) {
            return Result.fail("课程评价删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getCourseRatingList",roles = {"ADMIN"},permission = "courseRating:read")
    @Operation(summary = "获取课程评价列表")
    public Result<List<EduCourseRatingVO>> getCourseRatingList() {
        List<EduCourseRatingVO> courseRatingList = eduCourseRatingService.getCourseRatingList();
        return Result.success(courseRatingList);
    }
}